package logic;

import java.nio.file.Path;
import java.util.ArrayList;

import view.Game;

import data.Card;
import data.User;


public class GameStarter {

	public ArrayList<Card> cards = new ArrayList<Card>();
	public ArrayList<Card> userCards = new ArrayList<Card>();
	public ArrayList<User> players = new ArrayList<User>();
	
	public void startTheGame(int state2) {
		
		String filename = "cards.txt";
		FileOperation fileOperation = new FileOperation();
		cards = fileOperation.getCardList(filename, cards);
		int size = cards.size();
		
		int randomCard = getRandom(size);
		cards.remove(randomCard);
		int cardSize = cards.size();
		ArrayList<User> genericPlayers;
		genericPlayers = generateUser(2,cardSize);
		generateGame(cards, genericPlayers);
		
	}

	

	private int getRandom(int size) {
		RandomCard randomNumberOfCards = new RandomCard();
		return randomNumberOfCards.randomNumber(size);
	}

	private void generateGame(ArrayList<Card> cards, ArrayList<User> genericPlayers) {
		
		Game game = new Game();
		game.gameStart(cards, genericPlayers);
		
	}


	private ArrayList<User> generateUser(int numbersOfUsers, int size) {
		for(int i = 0; i < numbersOfUsers; i++){
			int numberUser = i + 1;
			String username = "Gammer no. " + numberUser;
			for(int k = 0; k < 4; k++ ){
				int rand = getRandom(size);
				userCards.add(cards.get(rand));
				cards.remove(rand);
			}
			User player = new User(username, 0, userCards);
			players.add(player);
		}
		
		return players;
	}


}
